#include <iostream>
#include <unordered_map>
#include <cmath>

bool isPrime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::unordered_map<std::string, int> wordsToNumbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4}, 
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };

    std::string input1, input2, input3;
    std::cin >> input1 >> input2 >> input3;
    if ((input1 == "zero" or input1 == "one" or input1 == "two" or input1 == "three" or input1 == "four" or input1 == "five" or input1 == "six" or input1 == "seven" or input1 == "eight" or input1 == "nine") and (input2 == "zero" or input2 == "one" or input2 == "two" or input2 == "three" or input2 == "four" or input2 == "five" or input2 == "six" or input2 == "seven" or input2 == "eight" or input2 == "nine") and (input3 == "zero" or input3 == "one" or input3 == "two" or input3 == "three" or input3 == "four" or input3 == "five" or input3 == "six" or input3 == "seven" or input3 == "eight" or input3 == "nine")){
        int number = wordsToNumbers[input1] * 100 + wordsToNumbers[input2] * 10 + wordsToNumbers[input3];
        if (number >= 100 && number <= 999) {
            int lower = number - 1;
            int upper = number + 1;
            while (true) {
                if (isPrime(lower)) {
                    std::cout << lower;
                    break;
                }
                if (isPrime(upper)) {
                    std::cout << upper;
                    break;
                }
                lower--;
                upper++;
            }
        } 
    }

    else {
        std::cout << "Wrong input";
        }

        return 0;
}